<?php
/**
 * @notes:
 * @return
 * @author: admin
 * @date: 2024/9/11
 */

namespace addons\shopro\controller\tokens;

use addons\shopro\controller\Common;
use addons\shopro\service\tokens\PledgeService;
use app\admin\model\shopro\tokens\Pledgelog;
use app\common\model\User;

class Pledge extends Common
{

    protected $noNeedLogin = ["index"];
    protected $noNeedRight = ['*'];


    /***
     * 质押参数列表
     * @notes:
     * @throws \think\exception\DbException
     * @author: 小谢
     * @date: 2024/9/11 13:49
     */
    public function index()
    {
        $this->success('获取成功',(new PledgeService())->getList());
    }


    //质押
    public function pledge()
    {
        $param=$this->request->only(['id', 'rep_password']);
        if ($this->svalidate($param,'.submit')) {
            $user = auth_user();
            $this->success("质押成功", (new PledgeService())->pledge($user, $param));
        }
    }

    //质押记录
    public function pLogs()
    {
        $user = auth_user();

        $params = $this->request->param();

        $pledgeLog = Pledgelog::where('user_id', $user->id)->with(['pledge']);

        $logs = $pledgeLog->order('id', 'desc')->paginate(request()->param('list_rows', 10))->toArray();

        $this->success('获取成功', $logs);
    }

}